<?php

class showStToolBar {

    public $config = array();
    public $addOn = array();

    public function __construct($config) {
        $this->config = $config;
        if (empty($this->config ['pluginDir']))
            $this->config ['pluginDir'] = $config['fileDir'].DIRECTORY_SEPARATOR;
        if(empty($this->config ['pluginPath']))
                $this->config ['pluginPath'] = WP_PLUGIN_URL . '/stSocialMediaToolbox/Toolboxes/' . $config ['plugin_name'] . '/';
       
        $this->loadLib();
        $this->excute();
    }

    public function loadLib() {        
        $fileDir = $this->config ['fileDir'];
        $version = $this->config ['plugin_version'];
        require_once $fileDir . '/libs/' . $version . '/classes/stcontroller.php';
        require_once $fileDir . '/libs/' . $version . '/classes/stmodel.php';
        require_once $fileDir . '/libs/' . $version . '/classes/stview.php';
        require_once $fileDir . '/libs/' . $version . '/classes/stfunctions.php';
        require_once $fileDir . '/libs/' . $version . '/functions/core.php';
        require_once $fileDir . '/functions.php';
        require_once $fileDir . '/controller.php';

    }

    public function excute() {        
        $config = $this->config;
        $config['tableOptions'] = 'wp_st_options';
        $controllerName = $config['plugin_name'] . "Controller";
        $controllerObject = new $controllerName($config);
        if(!isset($_REQUEST['external'])){
            echo '<link href="' . $controllerObject->config ['backendCss'] . 'style.css" rel="stylesheet" type="text/css" />' . "\n";
            echo '<link href="' . $controllerObject->config ['backendCss'] . 'toolbar/toolbar.css" rel="stylesheet" type="text/css" />' . "\n";
            echo '<link href="' . $controllerObject->config ['frontendCss'] . 'facebook/fb.css" rel="stylesheet" type="text/css" />' . "\n";
            echo '<link href="' . $controllerObject->config ['frontendCss'] . 'facebook/my.css" rel="stylesheet" type="text/css" />' . "\n";
        }
        $action = $_REQUEST['action'];
        if(!empty($action)){
            echo $controllerObject->getAction($action);
        }else{
            echo $controllerObject->getAction('showToolBar');
        }
        die;
    }

}

$fileDir =  dirname(__FILE__);
$dir_file1 = explode(DIRECTORY_SEPARATOR.'wp-content'.DIRECTORY_SEPARATOR, $fileDir);
define('ABSPATH_FB', $dir_file1[0] . '/');
require_once( ABSPATH_FB . 'wp-load.php' );

$fileDir =  dirname(__FILE__);
$fileDir = str_replace(DIRECTORY_SEPARATOR.'cronjob', '', $fileDir);
$config = include $fileDir . DIRECTORY_SEPARATOR.'config.php';
$config['fileDir'] = $fileDir;
$pluginClass = new showStToolBar($config);

?>